<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线考试系统 - 登录</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
</head>
<body>
    <div class="login-container">
        <h2 class="login-title">在线考试系统</h2>
        <form id="loginForm" action="/on_line_exam_system/login.user" method="post">
            <div class="form-group">
                <input type="text" class="form-control" id="username" name="username" placeholder="用户名" required>
            </div>
            <div class="form-group">
                <input type="password" class="form-control" id="password" name="password" placeholder="密码" required>
            </div>
            <button type="submit" class="btn btn-primary btn-login">登录</button>
            <div class="register-link">
                <a href="register.html">没有账号？立即注册</a>
            </div>
        </form>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '/on_line_exam_system/login.user',
                    type: 'POST',
                    data: {
                        username: $('#username').val(),
                        password: $('#password').val()
                    },
                    success: function(response) {
                        if (response.success) {
                            window.location.href = response.redirect;
                        } else {
                            alert(response.message || '登录失败');
                        }
                    },
                    error: function() {
                        alert('登录失败，请稍后重试');
                    }
                });
            });
        });
    </script>
</body>
</html>